﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SiteFox.Business.Manager
{
    public static class BlogComment
    {
        public static IList<Model.BlogComment> GetByBlogPost(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.BlogComment where c.ID_BlogPost == _ID orderby c.Created descending select c;
            return _Query.ToList();
        }
        public static Model.BlogComment GetByID(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.BlogComment where c.ID == _ID select c;
            if (_Query.Count() > 0)
            {
                return _Query.Single();
            }
            else
            {
                return null;
            }
        }
        public static void Create(Model.BlogComment _BlogComment)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            _Entities.AddToBlogComment(_BlogComment);
            _Entities.SaveChanges();
        }
        public static void Edit(Model.BlogComment _BlogComment)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.BlogComment where c.ID == _BlogComment.ID select c;
            var __BlogComment = _Query.Single();
            __BlogComment.Created = _BlogComment.Created;
            __BlogComment.CreatedBy = _BlogComment.CreatedBy;
            __BlogComment.ID_BlogPost = _BlogComment.ID_BlogPost;
            __BlogComment.Text = _BlogComment.Text;
            __BlogComment.Title = _BlogComment.Title;
            _Entities.SaveChanges();
        }
        public static void Delete(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.BlogComment where c.ID == _ID select c;
            var _BlogComment = _Query.Single();
            _Entities.BlogComment.DeleteObject(_BlogComment);
            _Entities.SaveChanges();
        }
    }
}
